package com.controller;


import com.domain.ArticleType;
import com.service.ArticleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/type")
public class ArticleTypeController {

    @Autowired
    private ArticleTypeService articleTypeService;

    @RequestMapping("/typeList")
    public ModelAndView typeList(ModelAndView modelAndView) {
        List<ArticleType> typeList = articleTypeService.selectAll();
        modelAndView.addObject("typeList", typeList);
        modelAndView.setViewName("type");
        return modelAndView;
    }

    @RequestMapping("/typeListUI")
    public String typeListUI(Model model) {
        List<ArticleType> typeList = articleTypeService.selectAll();
        model.addAttribute("typeList", typeList);
        return "articleTypeList";
    }

    @RequestMapping("/addUI")
    public String addUI() {
        return "typeAdd";
    }


    @RequestMapping("/insert")
    public String insert(ArticleType articleType) {
        articleTypeService.insert(articleType);
        return "redirect:/type/typeListUI";
    }
}
